Skip to content

fix: cleanup pending acks on timeout to prevent memory leak#5442

Closed
seungeonchoi wants to merge 1 commit intosocketio:mainfrom
seungeonchoi:fix/emitWithAck-memory-leak
Closed

fix: cleanup pending acks on timeout to prevent memory leak#5442
seungeonchoi wants to merge 1 commit intosocketio:mainfrom
seungeonchoi:fix/emitWithAck-memory-leak

Conversation

@seungeonchoi
Copy link
Contributor

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behavior

When using emitWithAck with a timeout, if clients don't respond and the timeout triggers, the ack callbacks remain in socket.acks Map indefinitely, causing a memory leak.

New behavior

The ack callbacks are cleaned up from socket.acks Map when the timeout occurs, preventing memory leak.

Other information (e.g. related issues)

Fixes #4984

When using `emitWithAck` with a timeout, if clients don't respond
and the timeout triggers, the ack callbacks remain in `socket.acks`
Map indefinitely, causing a memory leak.

This fix:
- Returns a cleanup function from `broadcastWithAck` that removes
  pending acks from all sockets that received the packet
- Calls the cleanup function when timeout occurs in broadcast-operator
- Adds test cases to verify acks are cleaned up after timeout

Fixes socketio#4984
darrachequesne pushed a commit that referenced this pull request Mar 2, 2026
When using `emitWithAck` with a timeout, if clients didn't respond
and the timeout triggers, the ack callbacks remained in `socket.acks`
Map indefinitely, causing a memory leak.

Related: #4984
@darrachequesne
Copy link
Member

Merged as da04267. Thanks a lot 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"emitWithAck" function leaks memory when acknowledgement timeout

2 participants